﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddOpLinesInfoForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.SystemManage.AddOpLinesInfoForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../lib/boot.js" type="text/javascript"></script>
    <style type="text/css">
        .actionIcons span
        {
            width: 16px;
            height: 16px;
            display: inline-block;
            background-position: 50% 50%;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <form id="form1" method="post">
    <fieldset style="border: solid 1px #aaa; padding: 5px; height: 400px;">
        <legend>操作人员对应产线</legend>
        <div class="mini-splitter" style="width: 100%; height: 370px;">
            <div size="50%" showcollapsebutton="true">
                <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                    <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a>
                </div>
                <div class="mini-fit">
                    <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="UserID"
                        showfooter="false" borderstyle="border:0;" selectonload="true">
                        <div property="columns">
                            <div type="indexcolumn" width="15">
                            </div>
                            <div field="LoginCode" width="120" headeralign="center" allowsort="true">
                                登录账号
                            </div>
                            <div field="FullName" width="120" headeralign="center" allowsort="true">
                                职员姓名
                            </div>
                            <div cellcls="actionIcons" name="action" width="40" headeralign="center" align="center"
                                renderer="onActionRenderer" cellstyle="padding:0;">
                                操作</div>
                        </div>
                    </div>
                </div>
            </div>
            <div showcollapsebutton="true">
                <div class="mini-fit">
                    <div id="grid2" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="LineID"
                        showfooter="false" borderstyle="border:0;" multiselect="true" allowcelledit="true">
                        <div property="columns">
                            <div type="indexcolumn" width="15">
                            </div>
                            <div type="checkboxcolumn" field="rowIschecked" truevalue="1" falsevalue="0" width="20px">
                            </div>
                            <div field="LineCode" width="100px" headeralign="center">
                                产线编号
                            </div>
                            <div field="LineName" width="100px" headeralign="center">
                                产线名称
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" iconcls="icon-save" onclick="onOk" style="width: 60px; margin-right: 20px;">
            保存</a> <a class="mini-button" iconcls="icon-cancel" onclick="onCancel" style="width: 60px;">
                取消</a>
    </div>
    </form>
    <script type="text/javascript">
        mini.parse();
        var action;
        var form = new mini.Form("form1");
        var gridUser = mini.get("grid1");
        var gridLine = mini.get("grid2");
        function add() {
            mini.open({
                url: "CommForm/UserForm.aspx",
                title: "人员信息", width: 800, height: 510,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                            var idMaps = {};
                            var datas = gridUser.getData();
                            for (var i = 0, l = datas.length; i < l; i++) {
                                var o = datas[i];
                                var id = o["UserID"];
                                idMaps[id] = o;
                            }
                            if (datas.length > 0) {
                                for (var i = data.length - 1; i >= 0; i--) {
                                    var o = data[i];
                                    var id = o["UserID"];
                                    if (idMaps[id] != null) data.removeAt(i);
                                }
                            }
                            gridUser.addRows(data);
                        }
                    }
                }
            });
        }

        function delRow(row_uid) {
            var row = gridUser.getRowByUID(row_uid);
            if (row) {
                gridUser.removeRow(row);
            }
        }
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var rowIndex = e.rowIndex;
            var s = '<span class="icon-remove" title="删除记录" onclick="delRow(' + uid + ')"></span>';
            return s;
        }
        function SaveData(userList, lineList) {
            var o = {};
            o.userList = userList;
            o.lineList = lineList;
            var json = mini.encode([o]);
            if (action == "new") {
                $.ajax({
                    url: "../Service/SystemManageHandler.ashx?action=AddOpLines",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
        }
        function getDatas() {
            var useritems = [];
            var lineitems = [];
            var userdata = gridUser.getData();
            for (var i = 0; i < userdata.length; i++) {
                useritems.push(userdata[i].UserID);
            }
            var linedata = gridLine.getData();
            for (var i = 0; i < linedata.length; i++) {
                if (linedata[i].rowIschecked == 1) {
                    lineitems.push(linedata[i].LineID);
                }
            }
            if (useritems.length <= 0) {
                mini.alert("人员不能为空，请添加！");
                return;
            }
            if (lineitems.length <= 0) {
                mini.alert("请选择产线！");
                return;
            }
            SaveData(useritems, lineitems);
        }
        ////////////////////
        //标准方法接口定义
        function SetData(data) {
            if (data.action == "new") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                action = data.action;
                $.ajax({
                    url: "../service/BasicDataManageHandler.ashx?action=GetLineListByCombobox",
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        gridLine.setData(o);
                    }
                });
            }
        }
        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function onOk(e) {
            getDatas();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
    </script>
</body>
</html>
